<template>
  <div class="edit-wrap">
    <x2-form ref="editform" :is-new="isNewRecord" :form-config="formConfig"></x2-form>
    <div class="bottom-btns">
      <x2-space></x2-space>
      <el-button @click="handleSubmit" type="primary">保存提交</el-button>
      <el-button @click="$emit('close')" type="warning">取消返回</el-button>
    </div>
  </div>
</template>

<script>
import { formConfig } from './config'
export default {
  name: 'Edit',
  data() {
    return {
      formConfig,
      isNewRecord: false,
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      if (this.$attrs.id) {
        console.log('get request', this.$attrs.id)
      } else {
        this.isNewRecord = true
        setTimeout(() => {
          this.$refs.editform.init({
            scenarioId: this.$uuid(),
            scenarioName: '',
            description: '',
            categorize: 'b673b073-6c5f-40e0-af0e-1c6cc4de345b',
          })
        }, 0)
      }
    },
    async handleSubmit() {
      const res = await this.$refs.editform.getData()
      if (res) this.$emit('confirm', res)
    },
  },
}
</script>
<style scoped>
.edit-wrap {
  /* width: 200px; */
}
.bottom-btns {
  display: flex;
  align-items: center;
}
</style>
